package com.weibo.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharacterEcoding implements Filter {
    @SuppressWarnings("unused")
	private  FilterConfig config;
    private  String encoding="ISO8859_1";
	public void destroy() {
			this.config=null;
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		   request.setCharacterEncoding(encoding);
		   chain.doFilter(request, response);
	}

	public void init(FilterConfig config) throws ServletException {
		this.config = config;
		String s = config.getInitParameter("encoding");
		if (s != null) {
			encoding = s;
		}
	}

}
